package com.ayit.car.service.impl;

import com.ayit.car.common.context.BaseContext;
import com.ayit.car.common.result.PageResult;
import com.ayit.car.pojo.dto.ModelsDTO;
import com.ayit.car.pojo.dto.ModelsPageQueryDTO;
import com.ayit.car.pojo.vo.ModelsVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ayit.car.pojo.Models;
import com.ayit.car.service.ModelsService;
import com.ayit.car.mapper.ModelsMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 为王下葬
* @description 针对表【models(汽车品牌商品表)】的数据库操作Service实现
* @createDate 2024-06-24 18:12:48
*/
@Service
public class ModelsServiceImpl extends ServiceImpl<ModelsMapper, Models>
    implements ModelsService{

    @Autowired
    private ModelsService modelsService;
    @Autowired
    private ModelsMapper modelsMapper;

    /**
     * 添加汽车品牌商品
     * @param modelsDTO
     */
    @Override
    public void insertModels(ModelsDTO modelsDTO) {
        Models models = new Models();
        BeanUtils.copyProperties(modelsDTO,models);

        models.setCreateUser(BaseContext.getCurrentId());

        modelsService.save(models);
    }

    /**
     * 修改汽车品牌商品
     * @param modelsDTO
     */
    @Override
    public void updateModels(ModelsDTO modelsDTO) {
        Models models = new Models();
        BeanUtils.copyProperties(modelsDTO,models);

        models.setUpdateUser(BaseContext.getCurrentId());
        modelsService.updateById(models);
    }

    /**
     * 批量删除汽车品牌商品
     * @param ids
     */
    @Override
    public void deleteModelsByIds(List<Long> ids) {
        modelsService.removeByIds(ids);
    }

    /**
     * 分页查询汽车品牌商品
     * @param modelsPageQueryDTO
     * @return
     */
    @Override
    public PageResult pageQuery(ModelsPageQueryDTO modelsPageQueryDTO) {
        PageHelper.startPage(modelsPageQueryDTO.getPage(),modelsPageQueryDTO.getPageSize());
        Page<ModelsVO> page = modelsMapper.pageQuery(modelsPageQueryDTO);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public String getModelName(Long modelId) {
        return modelsMapper.getModelName(modelId);
    }

}




